package com.wbtech.cobub;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

public class CobubMainActivity extends TabActivity implements OnTabChangeListener{
    /** Called when the activity is first created. */
    @Override
	 public void onCreate(Bundle savedInstanceState)
	 {
	        super.onCreate(savedInstanceState);
	        requestWindowFeature(Window.FEATURE_NO_TITLE);
	        TabHost tabHost = getTabHost();
	        tabHost.addTab(tabHost.newTabSpec("1").setIndicator("CELL",this.getResources().getDrawable(R.drawable.cell)).setContent(new Intent(this, CellActivity.class)));
	        tabHost.addTab(tabHost.newTabSpec("2").setIndicator("GPS",this.getResources().getDrawable(R.drawable.gps)).setContent(new Intent(this, GPSActivity.class)));
	        tabHost.addTab(tabHost.newTabSpec("3").setIndicator("WIFI",this.getResources().getDrawable(R.drawable.wifi)).setContent(new Intent(this, WIFIActivity.class)));
	        tabHost.addTab(tabHost.newTabSpec("4").setIndicator("IP",this.getResources().getDrawable(R.drawable.ip)).setContent(new Intent(this, IPActivity.class)));
	        tabHost.addTab(tabHost.newTabSpec("4").setIndicator("地址",this.getResources().getDrawable(R.drawable.address)).setContent(new Intent(this, AddressActivity.class)));
	 }

	
	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		
	}
	
	
	
	 @Override public boolean onCreateOptionsMenu(Menu menu) {
	    	super.onCreateOptionsMenu(menu);
	    	getMenuInflater().inflate(R.menu.mainmenu, menu);
	    	return true; }

	    @Override
	    public boolean onOptionsItemSelected(MenuItem item){
		    /** Select statement to handle calls
		    to specific menu items */
		    switch (item.getItemId())
		    {
			    case R.id.itemExit:
			    	ExitDialog(CobubMainActivity.this).show();
			    	return true;
			    case R.id.itemAbout:
			    	Intent aboutIntent = new Intent(CobubMainActivity.this,AboutActivity.class);
			    	startActivity(aboutIntent);
		    }
		    return true;
	    }
	    
	    private Dialog ExitDialog(Context context) {
			AlertDialog.Builder builder = new AlertDialog.Builder(context);
			builder.setIcon(R.drawable.icon);
			builder.setTitle("Cobub提示");
			builder.setMessage("确定要退出么?");
			builder.setPositiveButton("确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int whichButton) {
							finish();
						}
					});
			builder.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int whichButton) {

						}
					});
			return builder.create();
		}
	   
	    @Override
		public boolean onKeyDown(int keyCode, KeyEvent event) {
			if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
				ExitDialog(CobubMainActivity.this).show();
				return true;
			}
			return super.onKeyDown(keyCode, event);
		}
}